#pragma once

#include "uv.h"
#include <memory>
#include <string>

namespace uvpp 
{
	enum class LoopMode
	{
		Default,
		New
	};

	enum class LoopStatus
	{
		StandBy,
		Running,
		Stopped
	};

	class EventLoop {
		using Deleter = void(*)(uv_loop_t*);

	public:
		EventLoop() = default;
		~EventLoop();

		static EventLoop *defaultLoop();

		int run();
		int stop();
		bool isRunInLoopThread();
		void runInThisLoop();

		uv_loop_t *raw();
		LoopStatus status();

	private:
		EventLoop(LoopMode mode);
		uv_thread_t _thread_id;
		LoopStatus _status;
		std::unique_ptr<uv_loop_t, Deleter> _loop;
	};

	using EventLoopPtr = std::shared_ptr<uvpp::EventLoop>;
}
